package com.lukk.controller;

import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.lukk.service.IMeasureIndentService;

/**
 * 
 * MeasureIndentController 下午1:19:00 Copyright zhaocj Inc. All Rights reserved.
 * alldios@outlook.com
 *
 */
@Controller
@RequestMapping("/measureIndent")
public class MeasureIndentController {
	private static Logger logger = LogManager.getLogger(MeasureIndentController.class.getName());
	@Resource
	private IMeasureIndentService measureIndentService;

	// 解析视图
	@RequestMapping("/workerIndent")
	public String workerMeasureIndent(Model model) {
		model.addAttribute("oneMenu", "workerIndentManage");
		model.addAttribute("twoMenu", "workerMeasureIndent");
		return "/cms/workerIndentManage/measureIndent";
	}

	// 解析视图
	@RequestMapping("/merchantIndent")
	public String merchantMeasureIndent(Model model) {
		model.addAttribute("oneMenu", "merchantIndentManage");
		model.addAttribute("twoMenu", "merchantMeasureIndent");
		return "/cms/merchantIndentManage/measureIndent";
	}

	/**
	 * 根据工人的注册省份分类分页查询信息
	 * 
	 * @param offset
	 * @param limit
	 * @param sort
	 * @param order
	 * @param merchantName
	 * @param phoneNumber
	 * @param beginTime
	 * @param endTime
	 * @param indentID
	 * @param indentStatus
	 * @param session
	 * @return
	 */
	@RequestMapping("/queryWorkerIndentByPage")
	public @ResponseBody Map<String, Object> queryWorkerIndentByPage(Integer offset, Integer limit, String sort,
			String order, String merchantName, String phoneNumber, String beginTime, String endTime, Integer indentID,
			Integer indentStatus, HttpSession session) {
		logger.debug("传入的参数对象是{},{},{},{},{},{},{},{},{},{}", offset, limit, sort, order, merchantName, phoneNumber,
				indentStatus, beginTime, endTime, indentID);
		Map<String, Object> retMap = null;
		try {
			retMap = measureIndentService.selectWorkerIndentByPage(offset, limit, sort, order, merchantName,
					phoneNumber, indentStatus, beginTime, endTime, indentID, session);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return retMap;
	}

	/**
	 * 根据分配的商户查询对应的订单的信息
	 * 
	 * @param offset
	 * @param limit
	 * @param sort
	 * @param order
	 * @param merchantName
	 * @param phoneNumber
	 * @param beginTime
	 * @param endTime
	 * @param indentID
	 * @param indentStatus
	 * @param session
	 * @return
	 */
	@RequestMapping("/queryMerchantIndentByPage")
	public @ResponseBody Map<String, Object> queryMerchantIndentByPage(Integer offset, Integer limit, String sort,
			String order, String merchantName, String phoneNumber, String beginTime, String endTime, Integer indentID,
			Integer indentStatus, HttpSession session) {
		logger.debug("传入的参数对象是{},{},{},{},{},{},{},{},{},{}", offset, limit, sort, order, merchantName, phoneNumber,
				indentStatus, beginTime, endTime, indentID);
		Map<String, Object> retMap = null;
		try {
			retMap = measureIndentService.selectMerchantIndentByPage(offset, limit, sort, order, merchantName,
					phoneNumber, indentStatus, beginTime, endTime, indentID, session);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return retMap;
	}

	/**
	 * 修改订单的状态
	 * @param indentID
	 * @param status
	 * @return
	 */
	@RequestMapping("/updateIndentStatus")
	public @ResponseBody boolean updateIndentStatus(Integer indentID, Integer status) {
		logger.debug("传入的参数对象是{},{}", indentID, status);
		boolean modifyFlag = false;
		try {
			modifyFlag = measureIndentService.modifyIndentStatus(indentID, status);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return modifyFlag;
	}
	/**
	 * 
	 * @param indentID  需要重新拍单的订单的ID
	 * @param workerID  接单的工人的ID
	 * @param indentStatus   订单的状态  主要分配已接单 （扣20元）  已经出发（扣50元）
	 * @return
	 */
	@RequestMapping("/reAllocateIndent")
	public @ResponseBody boolean reAllocateIndent(Integer indentID,Integer workerID,Integer indentStatus) {
		logger.debug("传入的参数对象是{}，{}，{}", indentID, workerID,indentStatus);
		try {
			measureIndentService.modifyForReallocatedIndent(indentID,workerID,indentStatus);
		} catch (Exception e) {
			
		}
		return true;
	}
	
}
